package com.turnengine.client.global.game.bean;

import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * The Game Version.
 */
public class GameVersion implements IGameVersion, Comparable<IGameVersion> {

	/** The id. */
	private int id = -1;
	/** The name. */
	private String name = "";
	/** The game id. */
	private int gameId = -1;

	/**
	 * Creates a new Game Version.
	 */
	public GameVersion() {
	}

	/**
	 * Creates a new Game Version.
	 * @param id the id
	 * @param name the name
	 * @param gameId the game id
	 */
	public GameVersion(int id, String name, int gameId) {
		setId(id);
		setName(name);
		setGameId(gameId);
	}

	/**
	 * Creates a new Game Version.
	 * @param gameVersion the game version
	 */
	public GameVersion(GameVersion gameVersion) {
		setId(gameVersion.getId());
		setName(gameVersion.getName());
		setGameId(gameVersion.getGameId());
	}

	/**
	 * Creates a new Game Version.
	 * @param iGameVersion the i game version
	 */
	public GameVersion(IGameVersion iGameVersion) {
		setId(iGameVersion.getId());
		setName(iGameVersion.getName());
		setGameId(iGameVersion.getGameId());
	}

	/**
	 * Returns the id.
	 * @return the id.
	 */
	public int getId() {
		return id;
	}

	/**
	 * Returns the name.
	 * @return the name.
	 */
	public String getName() {
		return name;
	}

	/**
	 * Returns the game id.
	 * @return the game id.
	 */
	public int getGameId() {
		return gameId;
	}

	/**
	 * Sets the id.
	 * @param id the id to set.
	 */
	public void setId(int id) {
		this.id = id;
	}

	/**
	 * Sets the name.
	 * @param name the name to set.
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * Sets the game id.
	 * @param gameId the game id to set.
	 */
	public void setGameId(int gameId) {
		this.gameId = gameId;
	}

	/**
	 * Returns the hash code.
	 * @return the hash code.
	 */
	@Override
	public int hashCode() {
		HashCodeBuilder hash = new HashCodeBuilder(53, 37);
		hash.append(id);
		hash.append(name);
		hash.append(gameId);
		return hash.toHashCode();
	}

	/**
	 * Returns true if this is equal to the given object.
	 * @param object the object to compare.
	 * @return true if this is equal to the given object.
	 */
	@Override
	public boolean equals(Object object) {
		if (object == this) {
			return true;
		}
		if (object instanceof GameVersion) {
			GameVersion compare = (GameVersion) object;
			EqualsBuilder equals = new EqualsBuilder();
			equals.append(this.id, compare.id);
			equals.append(this.name, compare.name);
			equals.append(this.gameId, compare.gameId);
			return equals.isEquals();
		}
		return false;
	}

	/**
	 * Compare this to the given object.
	 * @param compare the object to compare to.
	 * @return the result of the comparison.
	 */
	@Override
	public int compareTo(IGameVersion compare) {
		CompareToBuilder builder = new CompareToBuilder();
		builder.append(this.id, compare.getId());
		builder.append(this.name, compare.getName());
		builder.append(this.gameId, compare.getGameId());
		return builder.toComparison();
	}

	/**
	 * Returns this as a string.
	 * @return this as a string.
	 */
	@Override
	public String toString() {
		ToStringBuilder string = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
		string.append("id", id);
		if (name != null) {
			string.append("name", name);
		}
		string.append("gameId", gameId);
		return string.toString();
	}
}
